Skip to content

feat: add app_context_changed event type#2633

Open
zimeg wants to merge 7 commits into
mainfrom
feat/app-context-changed-event
Open

feat: add app_context_changed event type#2633
zimeg wants to merge 7 commits into
mainfrom
feat/app-context-changed-event

Conversation

@zimeg

@zimeg zimeg commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

This pull request adds the app_context_changed event type to @slack/types. The event fires in the agent DM (agent_view) experience when the user's surrounding context changes (e.g. they navigate to a channel, canvas, list, or message).

  • Adds AppContextChangedEvent to the SlackEvent discriminated union, covering the context entity kinds: slack#/types/channel_id, slack#/types/canvas_id, slack#/types/list_id, and slack#/types/message_context.
  • Adds an app_context field to GenericMessageEvent, since the same context is delivered inline on messages.

Scoped to the type definitions only — handling the event is left to consumers (e.g. Bolt and the sample apps).

Testing

Subscribe to the event and let TypeScript narrow each entity by its type:

app.event('app_context_changed', async ({ event }) => {
  if (!event.context.entities) return;

  for (const entity of event.context.entities) {
    switch (entity.type) {
      case 'slack#/types/channel_id':
      case 'slack#/types/canvas_id':
      case 'slack#/types/list_id':
        console.log(entity.type, entity.value); // value: string
        break;
      case 'slack#/types/message_context':
        console.log(entity.value.message_ts, entity.value.channel_id); // value: { message_ts, channel_id }
        break;
    }
  }
});

Requirements

@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9bbfc4e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@slack/types Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.90%. Comparing base (07744de) to head (9bbfc4e).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2633   +/-   ##
=======================================
  Coverage   88.90%   88.90%           
=======================================
  Files          63       63           
  Lines       10256    10256           
  Branches      452      452           
=======================================
  Hits         9118     9118           
  Misses       1117     1117           
  Partials       21       21           
Flag Coverage Δ
cli-hooks 88.90% <ø> (ø)
cli-test 88.90% <ø> (ø)
logger 88.90% <ø> (ø)
oauth 88.90% <ø> (ø)
socket-mode 88.90% <ø> (ø)
web-api 88.90% <ø> (ø)
webhook 88.90% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zimeg zimeg added enhancement M-T: A feature request for new functionality semver:minor pkg:types applies to `@slack/types` labels Jun 30, 2026
@zimeg zimeg self-assigned this Jun 30, 2026
@zimeg zimeg added the pkg:web-api applies to `@slack/web-api` label Jun 30, 2026
@zimeg zimeg added this to the types@next milestone Jun 30, 2026
zimeg added 2 commits June 29, 2026 17:11
…on setSuggestedPrompts

Adds AppContextChangedEvent to @slack/types with typed entity discriminated
union (channel_id, canvas_id, list_id, message_context). Also adds
app_context field to GenericMessageEvent since the context is delivered
inline on messages too.

Makes thread_ts optional on AssistantThreadsSetSuggestedPromptsArguments
in @slack/web-api since agent_view DMs don't require it.
@zimeg zimeg force-pushed the feat/app-context-changed-event branch from 4b3651b to ed43a3a Compare June 30, 2026 00:12
@zimeg zimeg removed the pkg:web-api applies to `@slack/web-api` label Jun 30, 2026
zimeg added 5 commits June 29, 2026 17:38
Validated against live socket-mode payloads:
- context.entities is optional — omitted when the context is empty or no
  referenced entity is visible to the user.
- message_context value carries only message_ts and channel_id; drop the
  unobserved user_id field.
The server drops any message_context entity without a channel_id before
emitting the event, so channel_id is always present on the wire. The
optionality lived only in server-side input validation, not the payload.
Adds tsd coverage for AppContextChangedEvent and the GenericMessageEvent
app_context field, with literals modeled on real socket-mode payloads:
each entity kind narrows by type, entities is optional (empty context),
and message_context requires channel_id.
@zimeg zimeg marked this pull request as ready for review June 30, 2026 01:18
@zimeg zimeg requested a review from a team as a code owner June 30, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement M-T: A feature request for new functionality pkg:types applies to `@slack/types` semver:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant